﻿@Master['Master'] @Section['Content']
<link href="/content/css/style.default.css" rel="stylesheet">
<link href="/content/css/select2.css" rel="stylesheet"/>
<link href="/content/css/bootstrap-select.min.css" rel="stylesheet"/>
<script>
function ValidateIPaddress(inputText)  
 {  
 var ipformat = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;  
 if(inputText.value.match(ipformat))  
 {  
 document.form1.text1.focus();  
 return true;  
 }  
 else  
 {  
 //alert("You have entered an invalid IP address!");  
// document.form1.text1.focus();<br>return false;  
 }  
 }  

Array.prototype.pushIfNotExist = function(val) {
    if (typeof(val) == 'undefined' || val == '') { return }
    val = $.trim(val)
    if ($.inArray(val, this) == -1) {
        this.push(val);
    }
};
$('form').submit(function(){
	alert($(this["options"]).val());
    return false;
});
$(function() {

var bloptions = new Array();
var selectlist = new Array();
   // var bl = $("[name='Blacklist']").attr("data-value").split(',');
     //$("[name='Blacklist']").val(bl);
//add to select table	 
//var option = '';
//for (i=0;i<bl.length;i++){
//   option += '<option value="'+ bl[i] + '">' + bl[i] + '</option>';
//}
//$('#blacklist').append(option);


     $('.selectpicker').selectpicker({
    //style: 'btn-info',
    //size: 4
    }); 
	$("select#blacklist option").map(function() {
//console.log($(this).val());
var option = $(this).val();
bloptions.push(option);
return $(this).val();
}).get();
var bl = "@Model.Config.Blacklist"
blarr = bl.split(',');
$.each(blarr, function(index, blvalue) { 
$.each(bloptions, function(index, ovalue) { 
  //console.log(value); 
if (blvalue == ovalue){
//$('.selectpicker').selectpicker('val',blvalue);
selectlist.push(blvalue);
}
});
});
$("[name='Blacklist']").val(selectlist.join(','));
$('.selectpicker').selectpicker('val', selectlist);
	$('.selectpicker').selectpicker('render');
    var ld = $("[name='LocalDomains']");
    var lm = $("[name='LocalMailBoxes']");
    if (ld.attr("data-value") != null) {
        ld.val(ld.attr("data-value").split(','));
    }
    if (lm.attr("data-value") != null) {
        lm.val(lm.attr("data-value").split(','));
    }
    $('[name=logLevel]').val('@Model.Config.logLevel');
	$('[name=updatetype]').val('@Model.Config.UpdateType');
    //$('[name=logLevel]').val( '@Model.Config.logLevel' );
    //$("[name='logLevel']").val("@Model.Config.logLevel").change();
    //$("[name='logLevel'] [value='@Model.Config.logLevel']").attr('selected',true);
    //$('[name=logLevel] option').filter(function() { 
    //  return ($(this).text() == '@Model.Config.logLevel'); //To select Blue
    //}).prop('selected', true); 
var initialText = $('.editable').val();
$('.editOption').val(initialText);
$('#test').change(function(){
var selected = $('option:selected', this).attr('class');
var optionText = $('.editable').text();
if(selected == "editable"){
  $('.editOption').show();
  $('.editOption').keyup(function(){
      var editText = $('.editOption').val();
      $('.editable').val(editText);
      $('.editable').html(editText);
  });
}else{
  $('.editOption').hide();
}
});
});
$(function() {
var selected = new Array();
  $('.selectpicker').on('change', function(){
    //var selected = $(this).find("option:selected").val();
	$('.selectpicker').selectpicker('render');
	$('.selected').each(function(){
	 var o = $('span.text', this).text()
	 //selected.pushIfNotExist(o);
	 selected.push(o);
	 //console.log(o);
});
//console.log(selected.join(","));
if(selected.length <= 0){
$("[name='Blacklist']").val(" ");
selected.length = 0;
} else {
$("[name='Blacklist']").val(selected.join(','));
selected.length = 0;
}
  });
  //Toggle True or False
$('.btn-toggle').click(function() {
var checked = $(this).find('input').val();
    $(this).find('.btn').toggleClass('active');  
    if ($(this).find('.btn-primary').size()>0) {
    	$(this).find('.btn').toggleClass('btn-primary');
		if (checked == null | checked !== "True" | checked !== "False" ){
		$(this).find('input').val("False");
		} 
		if (checked == "True") {
		$(this).find('input').val("False");
	}
	if (checked == "False") {
		$(this).find('input').val("True");
    }
}
    if ($(this).find('.btn-danger').size()>0) {
    	$(this).find('.btn').toggleClass('btn-danger');
    }
    if ($(this).find('.btn-success').size()>0) {
    	$(this).find('.btn').toggleClass('btn-success');
    }
    if ($(this).find('.btn-info').size()>0) {
    	$(this).find('.btn').toggleClass('btn-info');
    }
    $(this).find('.btn').toggleClass('btn-default');
});

         $(document).ready(function() {
			$('.btn-toggle').each(function() {
		var checked = $(this).find('input').val();
		var boolchk = $(this).find('.btn').html();
		if (checked == "True") {
		$(this).find('.btn').toggleClass('active');
		if ($(this).find('.btn-primary').size()>0) {
			$(this).find('.btn').toggleClass('btn-primary');
			$(this).find('.btn').toggleClass('btn-default');
			if (boolchk == "ON"){
			}
		}
		if (checked == "False"){
		$(this).find('.btn').toggleClass('btn-default');
		}
	}
});
			// This will empty first option in select to enable placeholder
                $('select option:first-child').text('');
                // Select2
                jQuery("select").select2({
                    minimumResultsForSearch: -1
                });
$(".spinner input").after('<span class="input-group-btn-vertical"> <button class="btn btn-default" type="button"><i class="fa fa-chevron-up fa-lg"></i></button>      <button class="btn btn-default" type="button"><i class="fa fa-chevron-down fa-lg"></i></button>    </span>');
            });
$(document).on('click','.spinner .btn:first-of-type', function(){
  var spin = $(this).parent().closest('div');
  
var isDisabled = $(spin).find('input').prop('disabled');
console.log(isDisabled);

  if($(spin).find('input').is(':disabled')){
     //textbox is disabled
	 console.log('disabled');
}
    $(spin).find('input').val( parseInt($(spin).find('input').val(), 10) + 1);
  });
  
  
  $(document).on('click','.spinner .btn:last-of-type', function(){
  var spin = $(this).parent().closest('div');
    $(spin).find('input').val( parseInt($(spin).find('input').val(), 10) - 1);
  });
 });
 
$(function() {
    var action;
    $(".number-spinner div").mousedown(function () {
        btn = $(this);
        input = btn.closest('.number-spinner').find('input');
        btn.closest('.number-spinner').find('div').prop("disabled", false);
    	if (btn.attr('data-dir') == 'up') {
            //action = setInterval(function(){
                if ( input.attr('max') == undefined || parseInt(input.val()) < parseInt(input.attr('max')) ) {
                    input.val(parseInt(input.val())+1);
                }else{
                    btn.prop("disabled", true);
                    clearInterval(action);
                }
            //}, 70);
    	} else {
           // action = setInterval(function(){
                if ( input.attr('min') == undefined || parseInt(input.val()) > parseInt(input.attr('min')) ) {
                    input.val(parseInt(input.val())-1);
                }else{
                    btn.prop("disabled", true);
                    clearInterval(action);
                }
            //}, 70);
    	}
    }).mouseup(function(){
        clearInterval(action);
    });
	
	});
</script>
<!-- mainwrapper -->
<div class="container settings">
		<div class="col-md-12 col-sm-6 col-xs-12">
			<div class="panel panel-default">
				<div class="panel-heading clearfix">
					<div class="pull-right">MachineID - @Model.StatsData.MachID</div>
					<h3 class="panel-title">Settings</h3>
				</div>
				<div class="panel-body">
					<form class="" action="/settings/update" method="POST">
						<div class="row">
							<div class="form-group col-md-3">
								<label class="col-sm-4">Dns Server</label>
								<input type="text" class="form-control" placeholder="" name="dnsServer" value="@Model.Config.dnsServer">
							</div>
							<div class="form-group col-md-3">
								<label class="col-sm-4">Log Path</label>
								<input type="text" class="form-control" placeholder="" name="logPath" value="@Model.Config.logPath">
							</div>
							<div class="form-group col-md-3">
								<label class="col-sm-6">Email Queue</label>
								<input type="text" class="form-control" placeholder="" name="storePath" value="@Model.Config.storePath">
							</div>
								<div class="form-group col-md-2">
									<label class="col-sm-8">Log Length</label>
									<div class="input-group spinner">
										<div class="input-group spinner"><input type="text" class="form-control" name="logLength" value="@Model.Config.logLength">
									</div>
								</div>
							</div>
					</div>
						<!-- row -->
						<div class="row">
							<div class="form-group col-md-2">
								<label class="col-sm-8">Host Name</label>
								<input type="text" class="form-control" placeholder="" name="HostName" value="@Model.Config.HostName">
							</div>
							<div class="form-group col-md-2">
								<label class="col-sm-8">Logging Level</label>
								<select class="width100p " data-placeholder="Choose debug level" name="logLevel">
									<option value=""></option>
									<option value="4">Debug</option>
									<option value="3">Info</option>
									<option value="2">Warn</option>
									<option value="1">Error</option>
									<option value="0">None</option>
								</select>
							</div>
							
								<div class="form-group col-md-2">
									<label class="col-sm-8">Queue Delay</label>
									<div class="input-group spinner">
										<input type="text" class="form-control" name="queuedelay" value="@Model.Config.queueDelay">
									</div>
								</div>
							
							<!-- form-group -->
						</div>
						<div class="panel-heading ">
							<h3 class="panel-title">Server Settings</h3>
						</div>
						<div class="row">
							<div class="form-group col-md-2">
								<label class="col-sm-8">Smtp Host</label>
								<input type="text" class="form-control" readonly="readonly" placeholder="my.domain.local" name="smtphost" value="@Model.Config.smtphost">
							</div>
							<div class="form-group col-md-2">
								<label class="col-sm-8">Smtp Port</label>
								<div class="input-group spinner">
									<input type="text" class="form-control" readonly="readonly" name="smtpport" value="@Model.Config.smtpport">
									</div>
							</div>
							<div class="form-group col-md-2">
								<label class="col-sm-8">Smtp Greeting</label>
								<input type="text" class="form-control" placeholder="Smtp Greeting" name="greeting" value="@Model.Config.greeting">
							</div>
							<div class="form-group col-md-2">
								<label class="col-sm-8">Enable Queue</label>
								<div class="btn-group btn-toggle">
									<input type="hidden" class="form-control" name="mailqueue" value="@Model.Config.mailQueue">
									<div class="btn btn-default">
										 ON
									</div>
									<div class="btn btn-primary active">
										 OFF
									</div>
								</div>
							</div>
							<div class="form-group col-md-2">
								<label class="col-sm-9">Enable Updates</label>
								<div class="btn-group btn-toggle">
									<input type="hidden" class="form-control" name="doupdates" value="@Model.Config.doUpdates">
									<div class="btn btn-default">
										 ON
									</div>
									<div class="btn btn-primary active">
										 OFF
									</div>
								</div>
							</div>
						</div>
						<!-- row -->
						<div class="row">
							<div class="form-group col-md-2">
								<label class="col-sm-8">Web Host</label>
								<input type="text" class="form-control" placeholder="Name" name="webhost" value="@Model.Config.webhost">
							</div>
							<div class="form-group col-md-2">
								<label class="col-sm-8">Web Port</label>
								<div class="input-group spinner">
									<input type="text" class="form-control" name="webport" value="@Model.Config.webport">
								</div>
							</div>
							<div class="form-group col-md-2">
								<label class="col-sm-8">Web ListenIP</label>
								<input type="text" class="form-control" placeholder="IP address" name="ListenIP" value="@Model.Config.ListenIP">
							</div>
							<div class="form-group col-md-2">
								<label class="col-sm-8">Store Data</label>
								<div class="btn-group btn-toggle">
									<input type="hidden" class="form-control" name="storedata" value="@Model.Config.StoreData">
									<div class="btn btn-default">
										 ON
									</div>
									<div class="btn btn-primary active">
										 OFF
									</div>
								</div>
							</div>
						</div>
						<!-- row -->
						<div class="row">
							<div class="form-group col-md-2">
								<label class="col-sm-9">Receive Timeout</label>
								<div class="input-group spinner">
									<input type="text" class="form-control" name="receivetimeout" value="@Model.Config.ReceiveTimeOut">
								</div>
							</div>
							<div class="form-group col-md-2">
								<label class="col-sm-8">Max Sessions</label>
								<div class="input-group spinner">
									<input type="text" class="form-control" name="maxsessions" value="@Model.Config.MaxSessions">
								</div>
							</div>
							<div class="form-group col-md-2">
								<label class="col-sm-10">Max Smtp Retry</label>
								<div class="input-group spinner">
									<input type="text" class="form-control" name="maxsmtpretry" value="@Model.Config.MaxSmtpRetry">
								</div>
							</div>
							<div class="form-group col-md-2">
								<label class="col-sm-10">Max Messages</label>
								<div class="input-group spinner">
									<input type="text" class="form-control" name="maxmessages" value="@Model.Config.MaxMessages">
								</div>
							</div>
						</div>
						<div class="panel-heading clearfix">
							<i class="icon-calendar"></i>
							<h3 class="panel-title">Security Settings</h3>
						</div>
						<div class="row">
							<div class="form-group col-md-4">
								<label class="col-sm-4">Local Domains</label>
								<input type="text" class="form-control" data-value="@Model.Config.LocalDomains" placeholder="LocalDomains" name="LocalDomains">
							</div>
							<div class="form-group col-md-4">
								<label class="col-sm-4">Local Mailboxes</label>
								<input type="text" class="form-control" data-value="@Model.Config.LocalMailBoxes" placeholder="LocalMailboxes" name="LocalMailboxes">
							</div>
							<div class="form-group col-md-4">
								<label class="col-sm-4">Blacklist Check</label>
								<input type="hidden" name="Blacklist">
								<select style="overflow:hidden;" id="blacklist" class="selectpicker form-control" data-container="body" data-width="auto" multiple title="select blacklists server" multiple data-selected-text-format="count" placeholder="select blacklists server">
									<option value="sbl-xbl.spamhaus.org">sbl-xbl.spamhaus.org</option>
									<option value="bl.spamcop.net">bl.spamcop.net</option>
									<option value="bb.barracudacentral.org">bb.barracudacentral.org</option>
									<option value="dnsbl-1.uceprotect.net">dnsbl-1.uceprotect.net</option>
									<option value="cbl.abuseat.org">cbl.abuseat.org</option>
									<option value="dnsbl-2.uceprotect.net">dnsbl-2.uceprotect.net</option>
									<option value="bl.mailspike.net">bl.mailspike.net</option>
									<option value="hostkarma.junkemailfilter.com">hostkarma.junkemailfilter.com</option>
									<option value="ubl.unsubscore.com">ubl.unsubscore.com</option>
									<option value="combined.njabl.org">combined.njabl.org</option>
								</select>
							</div>
						</div>
						<div class="row">
							<div class="form-group col-md-2">
								<label class="col-sm-8">Check Interval</label>
								<div class="input-group spinner">
									<input type="text" class="form-control" name="checkinterval" value="@Model.Config.CheckInterval">
									</div>
							</div>
							<div class="form-group col-md-2">
								<label class="col-sm-8">Update Type</label>
								<select class="width100p " data-placeholder="Choose update type" name="updatetype">
									<option value=""></option>
									<option value="stable">Stable</option>
									<option value="beta">Beta</option>
								</select>
							</div>
							<div class="form-group col-md-4">
								<label class="col-sm-4">Update URL</label>
								<input type="text" class="form-control" value="@Model.Config.UpdateUri" placeholder="UpdateSite" name="UpdateUri">
							</div>
						</div>
						<button type="submit" class="btn btn-primary">Finish</button>
					</form>
					<!-- Row end -->				
			</div>
		</div>
	</div>
	<script src="/content/js/bootstrap-select.min.js"></script>
	<script src="/content/js/jquery.validate.min.js"></script>
	<script src="/content/js/select2.min.js"></script>
@EndSection